package aliyun

import (
	"fmt"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
	"github.com/schollz/progressbar/v3"
)

type AliOssProgressListener struct {
	bar *progressbar.ProgressBar //第三方进度条库的类型
}

func NewAliOssProgressListener() *AliOssProgressListener {
	return &AliOssProgressListener{}
}

//需要满足ProgressListener接口的方法，里面是进度条实现逻辑
func (l *AliOssProgressListener) ProgressChanged(event *oss.ProgressEvent) {
	switch event.EventType {
	case oss.TransferStartedEvent:
		l.bar = progressbar.DefaultBytes(
			event.TotalBytes,
			"文件上传ing",
		)
	case oss.TransferDataEvent:
		l.bar.Add64(event.RwBytes)
	case oss.TransferCompletedEvent:
		fmt.Printf("\n上传完成\n")
	case oss.TransferFailedEvent:
		fmt.Printf("\n上传失败\n")
	default:
	}
}
